<?php

namespace Xrfg\Api\Trading\Account\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Xrfg\Core\Trading\Account\Models\Coin;

class WithdrawRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'coin_id' => ['required', 'integer', 'exists:trading_coins,id'],
            'address' => ['required', 'walletAddressValidator:'.$this->input('coin_id').','.$this->input('chain_name')],
            'number' => ['required', 'numeric', 'min:0.0000000000001'],
            'pay_password' => ['required', 'payPassword'],
            'note' => ['nullable'],
            'tag' => ['nullable'],
        ];

        $coin = Coin::find($this->input('coin_id'));
        if ($coin && 'USDT' == $coin->name) {
            $rules['chain_name'] = ['required', Rule::in(['OMNI', 'ERC20', 'TRC20'])];
        }

        return $rules;

    }
}
